package org.jash.shop2112.main

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import dagger.hilt.android.AndroidEntryPoint
import org.jash.shop2112.R
import org.jash.shop2112.databinding.ActivityMainBinding
import org.jash.shop2112.mvvm.BaseActivity
import org.jash.shop2112.utils.Event
import org.jash.shop2112.utils.log

@Route(path = "/shop/main")
@AndroidEntryPoint
class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
    override fun initData() {
    }

    override fun initView() {
        binding.navigation.setOnItemSelectedListener {
            supportFragmentManager.beginTransaction()
                .replace(R.id.container, ARouter.getInstance().build(
                    when(it.itemId) {
                        R.id.category -> "/shop/category"
                        R.id.cart -> "/shop/cart"
                        R.id.mine -> "/shop/mine"
                        else -> "/shop/home"
                    }
                ).navigation() as Fragment).commit()
            true
        }
        binding.navigation.selectedItemId = R.id.home
    }
    @Event("updateCartSize")
    fun updateCartSize(num:Int) {
        val badge = binding.navigation.getOrCreateBadge(R.id.cart)
        badge.isVisible = num != 0
        badge.number = num
    }

}